var CorrenaAssistant = Class.create(AbstractModule, {

setupWidgets: function() {

		//About
		this.controller.setupWidget(Mojo.Menu.appMenu, {
			omitDefaultItems: true
		}, {
			visible: true,
			items: [
      		Mojo.Menu.editItem,
			{ label: "Disclaimer", command: "do-disclaimer" },					
				{ label: "License", command: "do-license" },
				{ label: "Help", command: "do-help" }
			]
		});

this.help = true;

	this.toggleunit =
	{
		modelProperty: 'togglestate',
		trueLabel: 'SI',
	falseLabel: 'US'
	};
	this.togglemodel = {
		togglestate: true
	};
	this.controller.setupWidget("unitField", this.toggleunit, this.togglemodel);
	this.controller.listen("unitField", Mojo.Event.propertyChanged, this.unitChanged.bindAsEventListener(this));
	
	this.controller.setupWidget("method", {
			label: "Method<sup>*</sup>",
			choices: [
				{ label: "Standard", value: 1},
				{ label: "Hillier", value: 0}
			]
		}, this.methodModel = {
			value: 1
		});
	


	this.controller.setupWidget("pnaField", {
		charsAllow: isValidFPNumber,
		modifierState: Mojo.Widget.numLock
	}, {value: sodium});
	
	this.controller.setupWidget("glucoseField", {
		charsAllow: isValidFPNumber,
		modifierState: Mojo.Widget.numLock
	}, {});
	
},


unitChanged: function() {
//change unit display in bmi scene
var unitchoice = this.togglemodel.togglestate;

if (!unitchoice){
$("pnaUnit").update("<span class=\"si\">mEq/l</span>");
$("glucoseUnit").update("<span class=\"si\">mg/dL</span>");
}

if (unitchoice){
$("pnaUnit").update("<span class=\"si\">mmol/L</span>");
$("glucoseUnit").update("<span class=\"si\">mmol/L</span>");;
}
},


	calculate: function() {
	var result = correnacalc(this.togglemodel.togglestate,this.methodModel.value, parseFloat($("pnaField").mojo.getValue()), parseFloat($("glucoseField").mojo.getValue()));

  sodium=result.sodium;
	
if (isNaN(result.correna)){
return errormsg;
}
else {
	return "The corrected sodium is " + result.correna;
}
	}
});




